package star.cloud.asme.base.mybatis;

import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import star.cloud.asme.base.dto.Result;

import java.util.List;

@RestController
public interface IBaseController<T> {

    @GetMapping("/getOneByCondition/{columnName}/{columnValue}")
    default Result<T> getOneByCondition(@PathVariable("columnName") String columnName, @PathVariable("columnValue") Object columnValue) {
        return Result.error();
    }

    @GetMapping("/getListByCondition/{columnName}/{columnValue}")
    default Result<List<T>> getListByCondition(@PathVariable("columnName") String columnName, @PathVariable("columnValue") Object columnValue) {
        return Result.error();
    }

    @PostMapping("/getListByConditions")
    default Result<List<T>> getListByConditions(T conditions) {
        return Result.error();
    }

    @PostMapping("/getListByConditionsWithPage")
    default Result<IPage<T>> getListByConditionsWithPage(T conditions) {
        return Result.error();
    }

    @PostMapping
    default Result<T> insertOne(T entity) {
        return Result.error();
    }

    @PutMapping
    default Result<T> updateOne(T entity) {
        return Result.error();
    }

    @PreAuthorize("hasAuthority('管理员')")
    @DeleteMapping("/physical/{id}")
    default Result<?> physicalDeleteById(@PathVariable("id") Long id) {
        return Result.error();
    }


    @DeleteMapping("/logical/{id}")
    default Result<?> logicalDeleteById(@PathVariable("id") Long id) {
        return Result.error();
    }

    @DeleteMapping("/deleteByKeyValue/{key}/{value}")
    default Result<?> deleteByKeyValue(@PathVariable String key, @PathVariable Object value) {
        System.out.println("key = " + key);
        System.out.println("value = " + value);
        return null;
    }

    //激活，将deleted变为0
    @GetMapping("/active/{id}")
    default Result<?> activeById(@PathVariable("id") Long id) {
        return Result.error();
    }

    @GetMapping("/tree")
    default Result<List<T>> getTree() {
        return Result.error();
    }

    @GetMapping("/exportToExcel")
    default void exportToExcel(HttpServletResponse response) {
        System.out.println(response);
    }

    @PostMapping("/importFromExcel/{creator}")
    default void importFromExcel(@PathVariable("creator") Long creator, MultipartFile file) {
    }

}
